<?php
namespace Sys\Controller;
use Common\Controller\BaseController;
class DictController extends BaseController{
	public function __construct(){
		parent::__construct();
	}
	private function page(){
			if($val = I('get.field')){
			$where = [
				'field' => $val, 
			];
		}else{
			$where =[];
		}
		$dict = M('dict'); 
		$res = $dict->where($where)->page($_GET['p'],'5')->select();
		$count  = $dict->where($where)->count();
		$Page  = new \Think\Page($count,5);
		$Page->setConfig('prev','上一页');
		$Page->setConfig('next','下一页');
		$Page->setConfig('header','%UP_PAGE% %FIRST% %LINK_PAGE% %END% %DOWN_PAGE%');
		$Page->setConfig('theme','%HEADER%');
		$show= $Page->show();
		$this->assign('page',$show);

		$this-> assign('dict', $res);
	}
	public function index(){
		$this->page();
		$list = M('dict')-> field('field')-> group('field')->select();
		$this-> assign('vvvo', $list);
		$this->display();
	}

	public function doDelDict(){
		$ids = I('post.ids');
		$taf = M('dict')-> delete($ids);
		if(!$taf){
			$msg = [
				'msg' 	=> '删除失败',
				'error' => 0,
			];
		}
	}

	public function doEditDict(){
		$id=I('post.dict_id');
		$case= M('dict')->where(['dict_id'=>$id])->select();
		if($case){
			if(M('dict')-> create()){
			M('dict')->save();
			$msg = [
				'msg' 	=> '修改失败',
				'error' => 0,
			];
		}}else{
			if(M('dict')-> create()){
			M('dict')->add();
			$msg = [
				'msg' 	=> '添加失败',
				'error' => 0,
			];
		}

		}
		
	}

	public function lastId(){
		$lastId=M('dict')->max('dict_id');
		$this->ajaxReturn($lastId);
	}
	public function search(){
		$arr = [];
		include './public/data/index.php';
		$regex = '/.*';
		$regex .= I('get.keyword');
		$regex .= '.*/';
		foreach($data as $v){
			if(preg_match($regex,$v)){
				$arr[] =$v;
			}
		}
		$this-> ajaxReturn($arr);
	}	
	
}
    